/*
 * @Author: viivLgr 
 * @Date: 2018-03-21 10:39:12 
 * @Last Modified by: viivLgr
 * @Last Modified time: 2018-03-21 23:29:01
 */
'use strict';
require('./index.css');
var _uitl = require('util/util.js');
var templateIndex = require('./index.string');
// 侧边导航
var navSide = {
    option: {
        name: '',
        navList: [
            {name: 'user-center', desc: '个人中心', href: './user-center.html'},
            {name: 'order-list', desc: '我的订单', href: './order-list.html'},
            {name: 'user-pass-update', desc: '修改密码', href: './user-pass-update.html'},
            {name: 'about', desc: '关于viivmall', href: './about.html'}
        ]
    },
    init: function(option){
        // 合并选项
        $.extend(this.option, option);
        this.renderNav();
        return this;
    },
    renderNav: function(){
        // 计算active数据
        for(var i = 0, len = this.option.navList.length; i < len; i++){
            if(this.option.navList[i].name === this.option.name){
                this.option.navList[i].isActive = true;
            }
        }
        // 渲染list数据
        var navHtml = _uitl.renderHtml(templateIndex, {
            navList: this.option.navList
        });
        // 把html放入容器
        $('.nav-side').html(navHtml);
    }
}

module.exports = navSide;